package com.cnap.multiclouldmgmt.service;

import com.cnap.multiclouldmgmt.model.RepByPage;
import com.cnap.multiclouldmgmt.model.k8sModels.EventModel;
import com.cnap.multiclouldmgmt.model.k8sModels.K8sClusterBasicModel;
import com.cnap.multiclouldmgmt.model.k8sModels.K8sClusterModel;
import com.cnap.multiclouldmgmt.model.privatecloud.CloudVendorInfo;
import com.cnap.multiclouldmgmt.model.vm.CheckDelVmModel;
import com.cnap.multiclouldmgmt.model.vm.VmCreateModel;
import com.cnap.multiclouldmgmt.model.vm.VmModel;
import io.fabric8.kubernetes.api.model.events.v1beta1.Event;

import java.util.List;

/**
 * @author dyq
 * 基础服务
 */
public interface MultiCloudMgmtService {

    /**
     * 新建一个集群
     * @param k8sClusterModel
     * @throws Exception
     */
    void addK8sCluster(K8sClusterModel k8sClusterModel) throws Exception;

    /**
     * 根据条件获取集群信息
     * @param cloudVendor
     * @param k8sClusterName
     * @param pageSize
     * @param pageNo
     * @param createUser
     * @return
     */
    RepByPage<K8sClusterModel> getK8sClusterInfos(String cloudVendor, String k8sClusterName,
                                                  int pageSize, int pageNo,String createUser);

    /**
     * 根据条件获取集群信息
     * @param cloudVendor
     * @param k8sClusterName
     * @param pageSize
     * @param pageNo
     * @param createUser
     * @return
     */
    RepByPage<K8sClusterModel> getK8sClusterInfos(String cloudVendor, String k8sClusterName,
                                                  int pageSize, int pageNo,String createUser,String accountName);

    /**
     * 根据条件获取集群信息
     * @param cloudVendor
     * @param k8sClusterName
     * @param pageSize
     * @param pageNo
     * @return
     */
    RepByPage<K8sClusterModel> getK8sClusterInfos(String cloudVendor, String k8sClusterName,
                                                  int pageSize, int pageNo);

    /**
     * 获取集群总数
     * @param cloudVendor
     * @param k8sClusterName
     * @return
     */
    int getK8sClusterNum(String cloudVendor,String k8sClusterName);

    /**
     *
     * @param cloudVendor
     * @param k8sClusterName
     * @param createUser
     * @return
     */
    int getK8sClusterNum(String cloudVendor,String k8sClusterName,String createUser);

    /**
     *
     * @param k8sClusterModel
     * @throws Exception
     */
    void editK8sClusterInfo(K8sClusterModel k8sClusterModel) throws Exception;

    /**
     *
     * @param k8sClusterIp
     */
    void delK8sCluster(String k8sClusterIp) throws Exception;

    /**
     *
     * @param cloudVendor
     * @param k8sClusterName
     * @return
     * @throws Exception
     */
    K8sClusterBasicModel getK8sClientByCloudVendorAndName(String cloudVendor, String k8sClusterName) throws Exception;

    /**
     *
     * @param cloudVendor
     * @param k8sClusterName
     * @return
     * @throws Exception
     */
    List<K8sClusterBasicModel> getK8sClientByCloudVendorAndName(String cloudVendor, String k8sClusterName,String accountName) throws Exception;

    /**
     *
     * @param k8sClusterIp
     * @return
     * @throws Exception
     */
    K8sClusterBasicModel getK8sClientByIp(String k8sClusterIp) throws Exception;

    /**
     *
     * @param k8sClusterName
     * @return
     */
    K8sClusterBasicModel getK8sClusterInfoByName(String k8sClusterName);

    /**
     *
     * @param k8sClusterName
     * @return
     */
    String getK8sClusterIpByName(String k8sClusterName);

    /**
     * 去重返回用户所有的建立的云商
     * @param creatUser 用户
     * @return List<String> 
     */
    List<String> getCloudVendorsByCreateUser(String creatUser);

    /**
     *
     * @param userName
     * @return
     */
    List<String> getK8sIpsByUserName(String userName);

    /**
     *
     * @return
     */
    List<String> getAllK8sClusterIps();

    /**
     *
     * @return
     */
    List<String> getAllK8sClusterNames();

    /**
     *
     * @param vmCreateModel
     * @return 集群的ip
     */
    String installK8sFramwork(VmCreateModel vmCreateModel) throws Exception;


    /**
     * 根据要创建的虚机信息，得到要建立或者已经建立的集群信息
     *
     * @param vmCreateModel
     * @return 集群的ip
     */
    K8sClusterModel getK8sClusterModelByVmCreateModel(VmCreateModel vmCreateModel);

    /**
     * 安装worker节点
     * @param k8sClusterName
     * @param vmModel
     * @param masterModel
     * @throws Exception
     */
    void installK8sWorker(String k8sClusterName,VmModel vmModel,VmModel masterModel,VmCreateModel vmCreateModel) throws Exception;

    /**
     * 安装woker节点
     * @param k8sClusterName
     * @param vmModel
     * @param masterModel
     * @param appType
     * @throws Exception
     */
    void installK8sWorker(String k8sClusterName,VmModel vmModel,VmModel masterModel,String appType,VmCreateModel vmCreateModel) throws Exception;

    /**
     * 根据区域获取
     * @param vmCreateModel
     * @return
     */
    K8sClusterModel getK8sClusterModelByZoneId(VmCreateModel vmCreateModel);

    /**
     * 根据区域获取
     * @param vmCreateModel
     * @return
     */
    K8sClusterModel getK8sClusterModelByZoneIdNoBizId(VmCreateModel vmCreateModel);

    /**
     *
     * @param resource
     * @return
     */
    EventModel transResourceToEventModel(Event resource,K8sClusterModel k8sClusterModel,String userName);

    /**
     *
     * @param k8sClusterBasicModel
     * @param vmJson
     */
    void updateVmJson(K8sClusterBasicModel k8sClusterBasicModel, String vmJson);

    /**
     *
     * @param checkDelVmModel
     * @return
     */
    CheckDelVmModel checkVmDelResult(CheckDelVmModel checkDelVmModel);

    /**
     * 把集群事件放入数据库
     * @param eventModel
     */
    public void putK8sEventToDb(EventModel eventModel);

    /**
     * 通知其他服务集群有变化
     */
    public void informOtherSvcClusterChange();


    /**
     * 通知其他服务集群有变化
     */
    public void informOtherSvcClusterChange(String clusterName);

    /**
     *
     * @param vmModel
     * @param userName
     * @return
     */
    List<K8sClusterModel> getK8sClusterInfosByZone(VmModel vmModel,String userName);

    List<CloudVendorInfo> getAllCloudVenderAccountInfo(String userName);

    void deControlK8sCluster(String k8sClusterIp);

    List<K8sClusterBasicModel> getAllGpuInUseClusterInfos();

    int getK8sClusterNum(String cloudVendor, String k8sClusterName, String createUser,String accountName);

    }
